<?php
/**
 * Created by PhpStorm.
 * User: tsy
 * Date: 2016/7/13
 * Time: 14:25
 */

namespace Admin\Controller\Facilitator;
use Think\Controller;

class FacilitatorController extends Controller{
    public function select_facilitator_info(){
        $fac_name=I("get.fac_name","");
        $facilitator=D("Facilitator");
        $result=$facilitator->select_facilitator_info($fac_name);
        echo json_encode($result);
    }
	/**
	 *	管理后台菜单初始化与用户登录身份验证
	 */
	public function _initialize() 
	{
		session('regist_id','232');
		// 判断用户是否登陆
		if (!session('?regist_id')) //	!session('?regist_id')
		{
			$url = 'http://' . $_SERVER['HTTP_HOST'] .'/tp_bypal/index.php';
			redirect($url);
			// echo "<script>alert('权限不足，无法操作');window.location.href='".$url."';</script>";
			exit;
		}
	}


	/**
	 *	审核商户列表页#####待审核、审核通过、审核未过
	 */
	public function pending_list() 
	{
		if (IS_GET && I('get.type')) 
		{
			$type = I('get.type');
			$this->assign('type',$type);

			$model = M('bypal_facilitator_info');
			$array_facilitatorInfo = $model->where('sign_type_id=1 or sign_type_id=2')->select();
			$array_exist = array();
			foreach ($array_facilitatorInfo as $key => $value) 
			{
				array_push($array_exist, $value['id']);
			}

			$shopby_table = M('shopby_table','','mysql://root:123456@120.24.52.49:3307/facilitator#utf8');
			if ($type == '3') 
			{
				$condition['mark'] = '0';
			}
			else
			{
				$condition['mark'] = $type;
			}
			$condition['facilitator_info_id'] = array('not in', $array_exist);
			if (I('get.select_name')) 
			{
				$condition['merchant_name'] = array('like','%'.I('get.select_name').'%');
			}
			if (I('get.select_user')) 
			{
				$condition['author'] = I('get.select_user');
			}
			if (I('get.select_time')) 
			{
				$condition['edttime'] = array(array('egt',strtotime(I('get.select_time'))),array('lt',strtotime(I('get.select_time'))+86400));
			}
			$array_list = $shopby_table->where($condition)->order('ctime desc')->select();
			foreach ($array_list as $key => $value) 
			{
				$array_list[$key]['regtime'] = date('Y-m-d', $value['regtime']);
				$array_list[$key]['edttime'] = date('Y-m-d', $value['edttime']);
			}

			$json_list = json_encode($array_list);
			$this->assign('json_list',$json_list);

			//	商务代表下拉框数据
			$model_user = D("bypal_comm_user");
			$array_user = $model_user->where('user_depart="0"')->select();
			$this->assign('array_user',$array_user);

			$this->display();
		}
	}


	/**
	 *	待审核商户列表页#####通过or未通过动作or重新提交审核
	 */
	public function facilitator_check() 
	{
		if ($_POST && array_key_exists('type', $_POST) && $_POST['type']) 
		{
			$type = $_POST['type'];
			$data = $_POST['checkData'];
			$content = $_POST['content'];

			$shopby_table = M('shopby_table','','mysql://root:123456@120.24.52.49:3307/facilitator#utf8');
			if ($type == '1') 
			{
				$shopby_table->mark = '1';
				$shopby_table->remark = $content;
			}
			elseif ($type == '2') 
			{
				$shopby_table->mark = '0';
				$shopby_table->remark = $content;
			}
			elseif ($type == '3') 
			{
				$shopby_table->mark = '2';
				$shopby_table->remark = '';
			}
			if ($shopby_table->where('id='.$data)->save()) 
			{
				$result = '1';
			}
			else
			{
				$result = '2';
			}
			$this->ajaxReturn($result);
		}
	}


	/**
	 *	审核资料详情
	 */
	public function checkinfo_see() 
	{
		if (IS_GET && I('get.id')) 
		{
			$id = I('get.id');
			$this->assign('id',$id);

			$this->display();
		}
		else
		{
			echo "<script>alert('地址错误，请正确操作！');history.back();</script>";
			exit;
		}
	}


	/**
	 *	审核资料详情#####获取表格数据
	 */
	public function get_checkinfo_see() 
	{
		if (IS_GET && I('get.id')) 
		{
			$shopby_table = M('shopby_table','','mysql://root:123456@120.24.52.49:3307/facilitator#utf8');
			$result = $shopby_table->where('id='.I('get.id'))->find();
			$result['edttime'] = date('Y-m-d', $result['edttime']);
			$result['regtime'] = date('Y-m-d', $result['regtime']);
			$this->assign('result',$result);

			$model_files = M('bypal_shopby_file');
			$array_files = $model_files->where('visitlog_id='.$result['visitlog_id'].' and file_mark="1"')->select();
			$this->assign('array_files',$array_files);

			$this->display();
		}
		else
		{
			echo "<script>alert('地址错误，请正确操作！');history.back();</script>";
			exit;
		}
	}


	/**
	 *	签约资料编辑
	 */
	public function signinfo_edit() 
	{
		if (IS_GET && I('get.id')) 
		{
			$data = I('get.id');
			$facilitator_info_id = I('get.facilitator_info_id');
			$this->assign('data',$data);
			$this->assign('facilitator_info_id',$facilitator_info_id);

			$model = M('bypal_facilitator_info');
			$result = $model->where('id='.$facilitator_info_id)->find();
			$this->assign('result',$result);

			$shopby_table = M('shopby_table','','mysql://root:123456@120.24.52.49:3307/facilitator#utf8');
			$data_shopby = $shopby_table->where('id='.I('get.id'))->find();
			$this->assign('data_shopby',$data_shopby);

			//	商户特定利率数据表格
			$array_rate = array();
			for ($i=0; $i < 40; $i++) 
			{ 
				$array_rate[$i]['value'] = '0';
			}
			if ($result['fac_rate_method'] == '1') 
			{
				$model_rate = M('bypal_facilitator_rate');
				$array_rate = $model_rate->where('fac_id='.$result['id'])->select();
			}
			$this->assign('array_rate',$array_rate);

			//	利率范围数据
			$array_selfrate = array();
			if ($result['fac_rate_method'] == '3') 
			{
				$model_selfrate = M('bypal_facilitator_selfrate');
				$array_selfrate = $model_selfrate->where('fac_id='.$result['id'])->find();
			}
			$this->assign('array_selfrate',$array_selfrate);

			//	经营类别下拉框数据
			$model_managementType = M('bypal_management_type');
			$array_managementType = $model_managementType->select();
			$this->assign('array_managementType',$array_managementType);

			//	服务分类下拉框数据
			$model_facilitatorItype = M('bypal_facilitator_itype');
			$array_facilitatorItype = $model_facilitatorItype->select();
			$this->assign('array_facilitatorItype',$array_facilitatorItype);

			//	签约状态下拉框数据
			$model_signState = M('bypal_sign_state');
			$array_signState = $model_signState->select();
			$this->assign('array_signState',$array_signState);

			//	签约银行下拉框数据
			$model_bankname = M('bypal_comm_bankname');
			$array_bankname = $model_bankname->select();
			$this->assign('array_bankname',$array_bankname);

			//	延期上限下拉框数据
			$model_utildelay = M('bypal_borrow_utildelay');
			$array_utildelay = $model_utildelay->select();
			$this->assign('array_utildelay',$array_utildelay);

			$this->display();
		}
		else
		{
			echo "<script>alert('地址错误，请正确操作！');history.back();</script>";
			exit;
		}
	}


	/**
	 *	签约资料编辑#####1.基本信息提交
	 */
	public function baseinfo_submit() 
	{
		if ($_POST && array_key_exists('baseinfo', $_POST) && $_POST['baseinfo']) 
		{
			$model = M('bypal_facilitator_info');
			if ($model->where('id='.$_POST['facilitator_info_id'])->find()) 
			{
				//	修改
				$update['man_type_id'] = $_POST['man_type_id'];
				$update['fac_name'] = $_POST['fac_name'];
				$update['fac_simple_name'] = $_POST['fac_simple_name'];
				$update['fac_separatetype'] = $_POST['fac_separatetype'];
				$update['fac_licence_type'] = $_POST['fac_licence_type'];
				$update['fac_licence_number'] = $_POST['fac_licence_number'];
				$update['fac_officialaddress'] = $_POST['fac_officialaddress'];
				$model->where('id='.$_POST['facilitator_info_id'])->save($update);

				$facilitator_info_id = $_POST['facilitator_info_id'];
			}
			else
			{
				//	新增
				$insert['man_type_id'] = $_POST['man_type_id'];
				$insert['fac_name'] = $_POST['fac_name'];
				$insert['fac_simple_name'] = $_POST['fac_simple_name'];
				$insert['fac_separatetype'] = $_POST['fac_separatetype'];
				$insert['fac_licence_type'] = $_POST['fac_licence_type'];
				$insert['fac_licence_number'] = $_POST['fac_licence_number'];
				$insert['fac_officialaddress'] = $_POST['fac_officialaddress'];
				$insert['fac_createTime'] = date('Y-m-d H:i:s', time());
				if ($result = $model->add($insert)) 
				{
					$model_shopby = M('shopby_table','','mysql://root:123456@120.24.52.49:3307/facilitator#utf8');
					$update_shopby['facilitator_info_id'] = $result;
					$model_shopby->where('id='.$_POST['baseinfo'])->save($update_shopby);

					$facilitator_info_id = $result;
				}
			}

			echo "<script>window.location.href='../../facilitator/facilitator/signinfo_edit?id=".$_POST['baseinfo']."&facilitator_info_id=".$facilitator_info_id."';</script>";
			exit;
		}
	}


	/**
	 *	签约资料编辑#####2.官网信息提交
	 */
	public function siteinfo_submit() 
	{
		if ($_POST && array_key_exists('siteinfo', $_POST) && $_POST['siteinfo']) 
		{
			$model = M('bypal_facilitator_info');
			$fac_pic = '';
			if ($_FILES['fac_pic']) 
			{
				$fac_pic = $this->uploaddata($_FILES['fac_pic']);
				if($fac_pic == 2 || $fac_pic == 3) 
				{
					$fac_pic = $_POST['fac_pic_name'];
				}
				// $fac_pic_address = '/tp_bypal/Public/upload/facilitator/'.$fac_pic;
			}

			$fac_app_pic = '';
			if ($_FILES['fac_app_pic']) 
			{
				$fac_app_pic = $this->uploaddata($_FILES['fac_app_pic']);
				if($fac_app_pic == 2 || $fac_app_pic == 3) 
				{
					$fac_app_pic = $_POST['fac_pic_name'];
				}
				// $fac_app_pic_address = '/tp_bypal/Public/upload/facilitator/'.$fac_app_pic;
			}

			if ($result = $model->where('id='.$_POST['facilitator_info_id'])->find()) 
			{
				//	修改
				if ($_FILES['fac_pic']) 
				{
					unlink("Public/upload/facilitator/".$result['fac_pic']);
					$update['fac_pic'] = $fac_pic;
				}

				if ($_FILES['fac_app_pic']) 
				{
					unlink("Public/upload/facilitator/".$result['fac_app_pic']);
					$update['fac_app_pic'] = $fac_app_pic;
				}
				
				$update['fac_introduction'] = $_POST['fac_introduction'];
				$update['fac_showphone'] = $_POST['fac_showphone'];
				$update['fac_showaddress'] = $_POST['fac_showaddress'];
				$model->where('id='.$_POST['facilitator_info_id'])->save($update);

				$facilitator_info_id = $_POST['facilitator_info_id'];
			}
			else
			{
				//	新增
				$insert['fac_introduction'] = $_POST['fac_introduction'];
				$insert['fac_showphone'] = $_POST['fac_showphone'];
				$insert['fac_showaddress'] = $_POST['fac_showaddress'];
				$insert['fac_pic'] = $fac_pic;
				$insert['fac_app_pic'] = $fac_app_pic;
				$insert['fac_createTime'] = date('Y-m-d H:i:s', time());
				if ($result2 = $model->add($insert)) 
				{
					$model_shopby = M('shopby_table','','mysql://root:123456@120.24.52.49:3307/facilitator#utf8');
					$update_shopby['facilitator_info_id'] = $result2;
					$model_shopby->where('id='.$_POST['siteinfo'])->save($update_shopby);

					$facilitator_info_id = $result2;
				}
			}

			echo "<script>window.location.href='../../facilitator/facilitator/signinfo_edit?id=".$_POST['siteinfo']."&facilitator_info_id=".$facilitator_info_id."';</script>";
			exit;
		}
	}


	/**
	 *	签约资料编辑#####3.联系信息提交
	 */
	public function links_submit() 
	{
		if ($_POST && array_key_exists('links', $_POST) && $_POST['links']) 
		{
			$model = M('bypal_facilitator_info');
			if ($model->where('id='.$_POST['facilitator_info_id'])->find()) 
			{
				//	修改
				$update['fac_corporation'] = $_POST['fac_corporation'];
				$update['fac_corporation_phone'] = $_POST['fac_corporation_phone'];
				$update['fac_corporation_email'] = $_POST['fac_corporation_email'];
				$update['fac_contact'] = $_POST['fac_contact'];
				$update['fac_contactphone'] = $_POST['fac_contactphone'];
				$update['fac_contactmailbox'] = $_POST['fac_contactmailbox'];
				$update['fac_phone'] = $_POST['fac_phone'];
				$update['fac_email'] = $_POST['fac_email'];
				$update['fac_province'] = $_POST['fac_province'];
				if ($_POST['fac_city']) 
				{
					$update['fac_city'] = $_POST['fac_city'];
				}
				$update['fac_address'] = $_POST['fac_address'];
				$update['sign_type_id'] = $_POST['sign_type_id'];
				$model->where('id='.$_POST['facilitator_info_id'])->save($update);

				$facilitator_info_id = $_POST['facilitator_info_id'];
			}
			else
			{
				//	新增
				$insert['fac_corporation'] = $_POST['fac_corporation'];
				$insert['fac_corporation_phone'] = $_POST['fac_corporation_phone'];
				$insert['fac_corporation_email'] = $_POST['fac_corporation_email'];
				$insert['fac_contact'] = $_POST['fac_contact'];
				$insert['fac_contactphone'] = $_POST['fac_contactphone'];
				$insert['fac_contactmailbox'] = $_POST['fac_contactmailbox'];
				$insert['fac_phone'] = $_POST['fac_phone'];
				$insert['fac_email'] = $_POST['fac_email'];
				$insert['fac_province'] = $_POST['fac_province'];
				if ($_POST['fac_city']) 
				{
					$insert['fac_city'] = $_POST['fac_city'];
				}
				$insert['fac_address'] = $_POST['fac_address'];
				$insert['sign_type_id'] = $_POST['sign_type_id'];
				$insert['fac_createTime'] = date('Y-m-d H:i:s', time());
				if ($result = $model->add($insert)) 
				{
					$model_shopby = M('shopby_table','','mysql://root:123456@120.24.52.49:3307/facilitator#utf8');
					$update_shopby['facilitator_info_id'] = $result;
					$model_shopby->where('id='.$_POST['links'])->save($update_shopby);

					$facilitator_info_id = $result;
				}
			}

			echo "<script>window.location.href='../../facilitator/facilitator/signinfo_edit?id=".$_POST['links']."&facilitator_info_id=".$facilitator_info_id."';</script>";
			exit;
		}
	}


	/**
	 *	签约资料编辑#####4.银行账号信息提交
	 */
	public function bankinfo_submit() 
	{
		if ($_POST && array_key_exists('bankinfo', $_POST) && $_POST['bankinfo']) 
		{
			$model = M('bypal_facilitator_info');
			if ($model->where('id='.$_POST['facilitator_info_id'])->find()) 
			{
				//	修改
				$update['fac_account_type'] = $_POST['fac_account_type'];
				$update['fac_bankcard'] = $_POST['fac_bankcard'];
				$update['fac_bankinfo'] = $_POST['fac_bankinfo'];
				$update['fac_branchbank'] = $_POST['fac_branchbank'];
				$update['fac_account_name'] = $_POST['fac_account_name'];
				$model->where('id='.$_POST['facilitator_info_id'])->save($update);

				$facilitator_info_id = $_POST['facilitator_info_id'];
			}
			else
			{
				//	新增
				$insert['fac_account_type'] = $_POST['fac_account_type'];
				$insert['fac_bankcard'] = $_POST['fac_bankcard'];
				$insert['fac_bankinfo'] = $_POST['fac_bankinfo'];
				$insert['fac_branchbank'] = $_POST['fac_branchbank'];
				$insert['fac_account_name'] = $_POST['fac_account_name'];
				$insert['fac_createTime'] = date('Y-m-d H:i:s', time());
				if ($result = $model->add($insert)) 
				{
					$model_shopby = M('shopby_table','','mysql://root:123456@120.24.52.49:3307/facilitator#utf8');
					$update_shopby['facilitator_info_id'] = $result;
					$model_shopby->where('id='.$_POST['bankinfo'])->save($update_shopby);

					$facilitator_info_id = $result;
				}
			}

			echo "<script>window.location.href='../../facilitator/facilitator/signinfo_edit?id=".$_POST['bankinfo']."&facilitator_info_id=".$facilitator_info_id."';</script>";
			exit;
		}
	}


	/**
	 *	签约资料编辑#####5.分期首付&利率信息提交
	 */
	public function downpayment_submit() 
	{
		if ($_POST && array_key_exists('downpayment', $_POST) && $_POST['downpayment']) 
		{
			$model = M('bypal_facilitator_info');
			if ($result = $model->where('id='.$_POST['facilitator_info_id'])->find()) 
			{
				//	修改
				$update['fac_payType'] = $_POST['fac_payType'];
				$update['fac_rate_method'] = $_POST['fac_rate_method'];
				$model->where('id='.$_POST['facilitator_info_id'])->save($update);

				$facilitator_info_id = $_POST['facilitator_info_id'];

				if ($_POST['fac_rate_method'] == '1') 
				{
					$model_rate = M('bypal_facilitator_rate');
					if ($model_rate->where('fac_id='.$result['id'])->select()) 
					{
						//	修改
						for($i = 0; $i < count($_POST['nodown_payment']); $i++) 
						{
							$array = $this->math_payment($i);
							$update_rate1['value'] = $_POST['nodown_payment'][$i];
							$update_rate1['period'] = $array['period'];
							$update_rate1['min_money'] = $array['min_money'];
							$update_rate1['max_money'] = $array['max_money'];
							$update_rate1['state'] = '2';
							$array_rate1 = $model_rate->where('fac_id='.$result['id'].' and state="2"')->select();
							$model_rate->where('id='.$array_rate1[$i]['id'])->save($update_rate1);
						}

						for ($i=0; $i < count($_POST['down_payment']); $i++) 
						{ 
							$array = $this->math_payment($i);
							$update_rate2['value'] = $_POST['down_payment'][$i];
							$update_rate2['period'] = $array['period'];
							$update_rate2['min_money'] = $array['min_money'];
							$update_rate2['max_money'] = $array['max_money'];
							$update_rate2['state'] = '1';
							$array_rate2 = $model_rate->where('fac_id='.$result['id'].' and state="1"')->select();
							$model_rate->where('id='.$array_rate2[$i]['id'])->save($update_rate2);
						}
					}
					else
					{
						//	新增
						for($i = 0; $i < count($_POST['nodown_payment']); $i++) 
						{
							$array = $this->math_payment($i);
							$insert_rate1['value'] = $_POST['nodown_payment'][$i];
							$insert_rate1['period'] = $array['period'];
							$insert_rate1['min_money'] = $array['min_money'];
							$insert_rate1['max_money'] = $array['max_money'];
							$insert_rate1['fac_id'] = $result['id'];
							$insert_rate1['state'] = '2';
							$model_rate->add($insert_rate1);
						}

						for ($i=0; $i < count($_POST['down_payment']); $i++) 
						{ 
							$array = $this->math_payment($i);
							$insert_rate2['value'] = $_POST['down_payment'][$i];
							$insert_rate2['period'] = $array['period'];
							$insert_rate2['min_money'] = $array['min_money'];
							$insert_rate2['max_money'] = $array['max_money'];
							$insert_rate2['fac_id'] = $result['id'];
							$insert_rate2['state'] = '1';
							$model_rate->add($insert_rate2);
						}
					}
				}
				elseif ($_POST['fac_rate_method'] == '3') 
				{
					$model_selfrate = M('bypal_facilitator_selfrate');
					if ($model_selfrate->where('fac_id='.$result['id'])->find()) 
					{
						//	修改
						$update_selfrate['min_rate'] = $_POST['min_rate'];
						$update_selfrate['max_rate'] = $_POST['max_rate'];
						$model_selfrate->where('fac_id='.$result['id'])->save($update_selfrate);
					}
					else
					{
						//	新增
						$insert_selfrate['min_rate'] = $_POST['min_rate'];
						$insert_selfrate['max_rate'] = $_POST['max_rate'];
						$insert_selfrate['fac_id'] = $result['id'];
						$model_selfrate->add($insert_selfrate);
					}
				}
			}
			else
			{
				//	新增
				$insert['fac_payType'] = $_POST['fac_payType'];
				$insert['fac_rate_method'] = $_POST['fac_rate_method'];
				$insert['fac_createTime'] = date('Y-m-d H:i:s', time());
				if ($id = $model->add($insert)) 
				{
					if ($_POST['fac_rate_method'] == '1') 
					{
						$model_rate = M('bypal_facilitator_rate');
						for($i = 0; $i < count($_POST['nodown_payment']); $i++) 
						{
							$array = $this->math_payment($i);
							$insert_rate1['value'] = $_POST['nodown_payment'][$i];
							$insert_rate1['period'] = $array['period'];
							$insert_rate1['min_money'] = $array['min_money'];
							$insert_rate1['max_money'] = $array['max_money'];
							$insert_rate1['fac_id'] = $id;
							$insert_rate1['state'] = '2';
							$model_rate->add($insert_rate1);
						}

						for ($i=0; $i < count($_POST['down_payment']); $i++) 
						{ 
							$array = $this->math_payment($i);
							$insert_rate2['value'] = $_POST['down_payment'][$i];
							$insert_rate2['period'] = $array['period'];
							$insert_rate2['min_money'] = $array['min_money'];
							$insert_rate2['max_money'] = $array['max_money'];
							$insert_rate2['fac_id'] = $id;
							$insert_rate2['state'] = '1';
							$model_rate->add($insert_rate2);
						}
					}
					elseif ($_POST['fac_rate_method'] == '3') 
					{
						$model_selfrate = M('bypal_facilitator_selfrate');
						$insert_selfrate['min_rate'] = $_POST['min_rate'];
						$insert_selfrate['max_rate'] = $_POST['max_rate'];
						$insert_selfrate['fac_id'] = $id;
						$model_selfrate->add($insert_selfrate);
					}

					$model_shopby = M('shopby_table','','mysql://root:123456@120.24.52.49:3307/facilitator#utf8');
					$update_shopby['facilitator_info_id'] = $id;
					$model_shopby->where('id='.$_POST['downpayment'])->save($update_shopby);

					$facilitator_info_id = $id;
				}
			}

			echo "<script>window.location.href='../../facilitator/facilitator/signinfo_edit?id=".$_POST['downpayment']."&facilitator_info_id=".$facilitator_info_id."';</script>";
			exit;
		}
	}


	/**
	 *	签约资料编辑#####6.商户特定利率信息提交
	 */
	public function rateinfo_submit() 
	{
		if ($_POST && array_key_exists('rateinfo', $_POST) && $_POST['rateinfo']) 
		{
			$model = M('bypal_facilitator_info');
			if ($model->where('id='.$_POST['facilitator_info_id'])->find()) 
			{
				//	修改
				$update['fac_period_type'] = $_POST['fac_period_type'];
				$update['fac_delay'] = $_POST['fac_delay'];
				$update['fac_delay_id'] = $_POST['fac_delay_id'];
				$model->where('id='.$_POST['facilitator_info_id'])->save($update);

				$facilitator_info_id = $_POST['facilitator_info_id'];
			}
			else
			{
				//	新增
				$insert['fac_period_type'] = $_POST['fac_period_type'];
				$insert['fac_delay'] = $_POST['fac_delay'];
				$insert['fac_delay_id'] = $_POST['fac_delay_id'];
				$insert['fac_createTime'] = date('Y-m-d H:i:s', time());
				if ($result = $model->add($insert)) 
				{
					$model_shopby = M('shopby_table','','mysql://root:123456@120.24.52.49:3307/facilitator#utf8');
					$update_shopby['facilitator_info_id'] = $result;
					$model_shopby->where('id='.$_POST['rateinfo'])->save($update_shopby);

					$facilitator_info_id = $result;
				}
			}

			echo "<script>window.location.href='../../facilitator/facilitator/signinfo_edit?id=".$_POST['rateinfo']."&facilitator_info_id=".$facilitator_info_id."';</script>";
			exit;
		}
	}


	//	文件上传
	public function uploaddata($onefile) 
	{
		if ($onefile['error'] === 0) 
		{
			$path = "Public/upload";
			if (!is_dir($path)) {mkdir($path,0777);}
			$path = $path . '/facilitator';
			if (!is_dir($path)) {mkdir($path,0777);}

			if($onefile ["size"] < 3000000) 
			{
				$file1 = time().rand(10, 99).strrchr($onefile["name"],".");
				$file2 = $path.'/'.$file1;
				if(move_uploaded_file($onefile["tmp_name"],$file2)) 
				{
					return $file1;
				}
				else
				{
					return 3;
				}
			}
			else
			{
				return 2;
			}
		}
		else
		{
			return 3;
		}
	}


	//	商户特定利率表格数据获取
	public function math_payment($i) 
	{
		$a = floor($i/4);
		switch($a) 
		{
			case 0:
				$period=6;
				break;
			case 1:
				$period=9;
				break;
			case 2:
				$period=12;
				break;
			case 3:
				$period=18;
				break;
			case 4:
				$period=24;
				break;
		}

		$b = $i%4;
		switch($b) 
		{
			case 0:
				$min_money=1999;
				$max_money=10000;
				break;
			case 1:
				$min_money=10000;
				$max_money=20000;
				break;
			case 2:
				$min_money=20000;
				$max_money=30000;
				break;
			case 3:
				$min_money=30000;
				$max_money=50000;
				break;
		}
		return array('period' => $period, 'min_money'=>$min_money, 'max_money'=>$max_money);
	}


	/**
	 *	审核通过商户列表页#####签约动作or解约动作（已签约列表页）
	 */
	public function signed() 
	{
		if ($_POST && array_key_exists('signedData', $_POST) && $_POST['signedData']) 
		{
			$data = $_POST['signedData'];
			$type = $_POST['type'];

			$model = M('bypal_facilitator_info');
			if ($type == '1') 
			{
				$update['sign_type_id'] = '1';
			}
			elseif ($type == '2') 
			{
				$update['sign_type_id'] = '2';
			}
			if ($model->where('id='.$data)->save($update)) 
			{
				$result = '1';
			}
			else
			{
				$result = '2';
			}
			$this->ajaxReturn($result);
		}
	}


	/**
	 *	签约商户列表页#####已签约、未签约
	 */
	public function signed_list() 
	{
		if (IS_GET && I('get.type')) 
		{
			$type = I('get.type');
			$this->assign('type',$type);

			$model = M('bypal_facilitator_info');
			$condition['sign_type_id'] = $type;
			$array_list = $model->where($condition)->order('fac_createTime desc')->select();
			foreach ($array_list as $key => $value) 
			{
				$model_managementType = M('bypal_management_type');
				$data_managementType = $model_managementType->where('man_type_id='.$value['man_type_id'])->find();
				$array_list[$key]['man_type'] = $data_managementType['man_type'];

				$model_facilitatorItype = M('bypal_facilitator_itype');
				$data_facilitatorItype = $model_facilitatorItype->where('trade_number="'.$value['fac_separatetype'].'"')->find();
				$array_list[$key]['separatetype'] = $data_facilitatorItype['name'];

				$array_list[$key]['fac_introduction'] = '';
			}
			$json_list = json_encode($array_list);
			$this->assign('json_list',$json_list);

			$this->display();
		}
	}

}